﻿//随机创建10个形状对象，计算面积和。使用简单工厂设计模式
abstract class Shape
{
    //public void Area()
    //{

    //}
    public abstract int DiffArea();
}

class Rectangle:Shape
{
    int x, y;
    public Rectangle(int x,int y)
    {
        this.x = x;
        this.y = y;
    }
    public override int DiffArea()
    {
        return x * y;
    }
}


class ShapeFactory
{
    public static Shape GetShape(int choice)
    {
        Shape shape = null;
        switch(choice)
        {
            case 0:
                Random ran = new Random();
                int x1 = ran.Next(1, 9);
                int y1 = ran.Next(1, 9);
                Console.WriteLine("长方形长为：{0}，宽为{1}",x1,y1 );
                shape = new Rectangle(x1,y1); break;
        }
        return shape;
    }
}

class Program
{
    static void Main(string[] args)
    {
        double AreaSum = 0;       
        Shape[] array = new Shape[10];
        for(int i = 0; i < array.Length; i++)
        {
            Random ran = new Random();
            int choice = 0;
            array[i] = ShapeFactory.GetShape(choice);
            AreaSum += array[i].DiffArea();
        }
        Console.WriteLine("10个图形的面积和为：{0}",AreaSum);
    }
}